import json
from django.http import HttpResponse
from booking.models import User
import requests
from datetime import date, datetime,timedelta
from django.core.cache import cache
from booking.cache.caches import idspop
def QDao(request):
    data = json.loads(request.body)
    ids = data['openid']
    openid = ids[13:]
    index = ids[8:11]
    for i in range(3):
        if index[i] == '*':
            continue
        else:
            break
    index = index[i:]
    keys = ids[:8]
    print(openid,index,keys)
    ids = cache.get(openid)
    nums = cache.get('nums')
    if not nums:
        cache.set('nums',0,24*60*60)
        nums = 0
    if ids:
        if str(ids[0]) == index:
            if cache.get('RJ')[ids[0]] == keys:
                ids[1] = True
                ids[2] = 3
                cache.set(openid,ids,24*60*60)
                lines = cache.get("linenums")
                if lines:
                    if openid in lines:
                        return HttpResponse(json.dumps({'ret':'F3',"nums":nums}))
                    lines.append(openid)
                else:
                    lines = [openid]
                nums += 1
                cache.set('nums',nums,24*60*60)
                cache.set('linenums',lines,24*60*60)
                idspop(openid)
                return HttpResponse(json.dumps({'ret':"F1","nums":nums}))
    return HttpResponse(json.dumps({'ret':"F2"}))

